home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FCLOSE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  617 b   |  23 lines

  1. /* fclose.c */
  2. #include <stdio.h>
  3. char file2[80],               /* Name of file to open */
  4. line[81];                    /* or lines from the file */
  5. FILE *inputfile;  /* File pointer to opened file */
  6. main()
  7. {
  8.      printf ("Enter name of file to open: ");
  9.      gets(file2);
  10.                     /* Open the file */
  11.      if ((inputfile = fopen(file2, "r")) == NULL)
  12.      {
  13.          printf ("Error opening file: %s\n", file2);
  14.          exit(0);
  15.      }
  16.      printf("==== Contents of input file ====\n");
  17.      while (fgets(line, 80, inputfile) != NULL)
  18.      {
  19.         printf(line);
  20.      }
  21.                     /* Now close the file and exit */
  22.      fclose(inputfile);
  23. }